< previous page page_397 next page >

Page 397
In Visual Basic 3, there were only a couple of ways to pass information from one form to another. None of these were very efficient, and none were encapsulated. One technique was to create a label on the form to be called and pass in the data to the Caption property of the form. This worked, but had the side effect of loading the form prior to setting the data on the form. If you needed to use that data in the Form_Load() event, it was too late.
Another method was to have the called form reference back to the calling forms controls to grab some pieces of data. This also worked, but now if you wanted to use this one form in another project, it had a link to another form, which you would also have to bring into the project.
Yet another technique was to create some global variables, set them, then perform a Show on the form. This also has some drawbacks in that you were now tied to global variables that were in yet another BAS module that you had to bring into your other project if you wanted to reuse the form. Global variables also have a nasty habit of being changed when you least expect it, thereby causing all sorts of unpredictable results in your application.
Starting with Visual Basic 4, you can now create properties on a form, pass the data to that form, and then use that data in the Form_Load() event. The reason this can be done is because setting properties on a form does not load the formit only sets up its data. Now you can copy the form to any other project, and it doesnt rely on any external forms or BAS files.
Examples Filenames: EmpType.frm and Emps.frm
To illustrate this technique, lets create a form for the Employee Types table from which you can select an employee type (see Figure 20.2).
8160-0397a.gif
Figure 20.2
The Employee Types form.

 
< previous page page_397 next page >

If you like this book, buy it!